﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MySql.Data.MySqlClient;
using System.Configuration;

namespace SindSaudeCamadas.Dados
{
    public class tvsindsaude
    {
        Conex conexao = new Conex();
        public String carregaVideoPrincipal()
        {
            string VideoPrincipal = "";
            MySqlCommand cmdSQL = new MySqlCommand();
            try
            {
                string conex = ConfigurationManager.AppSettings["SindSaude"].ToString();
                cmdSQL.Connection = conexao.retornaConexao(conex);

                cmdSQL.CommandType = CommandType.Text;
                cmdSQL.CommandText = "select *,cast(concat('tvsindsaude.aspx?a=', id) as char) as url  from tbalbuns where publico = 2 order by datCriacao desc;";

                cmdSQL.Connection.Open();
                VideoPrincipal = (string)cmdSQL.ExecuteScalar().ToString();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                cmdSQL.Connection.Dispose();
                cmdSQL.Dispose();
                
            }
            return VideoPrincipal;

        }
        public DataTable carregaVideos()
        {
            DataTable dt = new DataTable();
            MySqlCommand cmdSQL = new MySqlCommand();
            MySqlDataAdapter daSQL = new MySqlDataAdapter();
            try
            {
                string conex = ConfigurationManager.AppSettings["SindSaude"].ToString();
                cmdSQL.Connection = conexao.retornaConexao(conex);

                cmdSQL.CommandType = CommandType.Text;
                cmdSQL.CommandType = CommandType.Text;
                cmdSQL.CommandText = "select *,cast(concat('tvsindsaude.aspx?a=', id) as char) as url  from tbalbuns where publico = 2 order by datCriacao desc;";

                cmdSQL.Connection.Open();
                daSQL.SelectCommand = cmdSQL;
                daSQL.Fill(dt);
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                cmdSQL.Connection.Dispose();
                cmdSQL.Dispose();
                daSQL.Dispose();
            }
            return dt;
        }
    
    }
}
